package com.xian.im.common.utils.template;

import com.alibaba.fastjson.JSONObject;
import com.xian.im.common.utils.sys.SpringContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;

/**
 * @program: xim
 * @description:
 * @author: liru.xian
 * @create: 2021-02-18 16:56
 **/
@Slf4j
public class RabbitTemplateUtil {


    /**
     * @param exchange
     * @param object
     */
    public static void sendMes(String exchange, Object object) {
        rabbitTemplate().convertAndSend(exchange, "", JSONObject.toJSONString(object));
    }

    /**
     * @param exchange
     * @param object
     */
    public static void sendMes(String exchange, String routingKey, Object object) {
        rabbitTemplate().convertAndSend(exchange, routingKey, JSONObject.toJSONString(object));
    }

    /**
     * @param exchange
     * @param object
     */
    public static void sendMes(String exchange, String routingKey, String object) {
        rabbitTemplate().convertAndSend(exchange, routingKey, object);
    }

    /**
     * @param queue
     * @param str
     */
    public static void sendMes(String queue, String str) {
        rabbitTemplate().convertAndSend(queue, str);
    }

    /**
     * 获取rabbitTemplate 模板 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
     *
     * @return
     */
    public static RabbitTemplate rabbitTemplate() {
        return SpringContextHolder.getBean(RabbitTemplate.class);
    }
}
